#include <iostream>
#include <cstdlib>

using namespace std;
typedef int T;

class Stack
{
	public:
		Stack():pHead(NULL), cnt(0){};
		Stack(const Stack &s):pHead(s.pHead),cnt(s.cnt){};
		void push(const T& d);
		void pop();
		int gettop();
		int empty(){ return cnt==0; }
		int size(){ return cnt; }
		void print();
	private:
		typedef struct Node
		{
			T data;
			struct Node *pNext;
		}NODE, *PNODE;
		PNODE pHead;
		int cnt;
};

void Stack::push(const T& d)
{
	PNODE pNew = new NODE;
	pNew->data=d;
	if(pHead==NULL)
	{
		pHead=pNew;
		pNew->pNext=NULL;
	}
	else
	{
		pNew->pNext=pHead;
		pHead=pNew;
	}
	cnt++;
}
void Stack::pop()
{
	if(empty())
	{
		cout<<"栈为空"<<endl;
	}
	else
	{
		PNODE p = pHead;
		pHead = pHead->pNext;
		delete p;
		cnt--;
	}
}
void Stack::print()
{
	PNODE p = pHead;
	while(p!=NULL)
	{
		cout<< p->data <<" ";
		p=p->pNext;
	}
	cout<<endl;
}
int Stack::gettop()
{
	if(empty())
	{
		cout << "栈为空！" << endl;
		exit(-1);
	}
	else
		return pHead->data;
}

int main()
{
	Stack s1;
	s1.push(0);
	s1.push(1);

	Stack s(s1);
	s.push(4);
	s.push(3);
	s.push(6);
	s.push(8);
	s.push(9);
	s.print();//打印全部
	cout<<"pop:"<<endl;
	s.pop();
	cout << "栈顶：" << s.gettop() << endl;
	cout << "栈的大小：" << s.size() << endl;
	s.print();//打印全部

	cout<<"pop:"<<endl;
	s.pop();
	cout << "栈顶：" << s.gettop() << endl;
	cout << "栈的大小：" << s.size() << endl;
	s.print();
}




























